package com.ruoyi.web.controller.topmes;

import com.alibaba.fastjson2.JSON;
import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.order.domain.MesTopOrder;
import com.ruoyi.order.proxy.factory.FactoryProxy;
import com.ruoyi.order.proxy.factory.req.*;
import com.ruoyi.order.proxy.factory.res.BarcodeResponse;
import com.ruoyi.order.proxy.factory.res.LineResponse;
import com.ruoyi.order.proxy.factory.res.OrderSeqResponse;
import com.ruoyi.order.proxy.factory.res.WorkShopResponse;
import com.ruoyi.order.service.IConfigService;
import com.ruoyi.order.service.IMesTopOrderService;
import com.ruoyi.web.controller.topmes.req.PlanOrderReq;
import com.ruoyi.web.controller.topmes.res.TopBaseRes;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@Slf4j
@RestController
@Anonymous
@RequestMapping("/topmes")
public class TopMesController extends BaseController {

    @Autowired
    private IMesTopOrderService mesTopOrderService;

    @Autowired
    private FactoryProxy factoryProxy;

    @Autowired
    private IConfigService configService;
    /**
     * 获取工厂车间列表
     * @return
     */
    @GetMapping("/getWorkshopList")
    public TableDataInfo getWorkshopList() {
        List<WorkShopResponse> list = factoryProxy.queryWorkShopList();
        return getDataTable(list);
    }

    /**
     * 获取工厂车间列表
     * @return
     */
    @GetMapping("/getBarcode/{orderNumber}")
    public AjaxResult getBarcode(@PathVariable("orderNumber") String orderNumber) {
        QueryBarcodeRequset queryBarcodeRequset = new QueryBarcodeRequset();
        queryBarcodeRequset.setDocno(orderNumber);
        BarcodeResponse response = factoryProxy.queryBarcodeByOrder(queryBarcodeRequset);
        return success( response);
    }

    /**
     * 获取订单工序列表
     * @return
     */
    @GetMapping("/getOrderSeqList/{orderNumber}")
    public TableDataInfo getOrderSeqList(@PathVariable("orderNumber") String orderNumber) {
        QuerySeqRequest querySeqRequest = new QuerySeqRequest();
        querySeqRequest.setAufnr(orderNumber);
        List<OrderSeqResponse> list = factoryProxy.queryOrderSeqByOrder(querySeqRequest);
        return getDataTable(list);
    }

    /**
     * 获取工厂车间列表
     * @return
     */
    @GetMapping("/getLineList/{workshopId}")
    public TableDataInfo getLineList(@PathVariable("workshopId") String workshopId) {
        QueryLineRequest queryLineRequest = new QueryLineRequest();
        queryLineRequest.setWorkshopid(workshopId);
        List<LineResponse> list = factoryProxy.queryLineList(queryLineRequest);
        return getDataTable(list);
    }
}
